﻿using PerfAnalyzerLib;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace UnitTests
{
	[TestClass]
	public class CounterInfoTest
	{
		/// <summary>
		/// Test without instance
		///</summary>
		[TestMethod]
		public void CounterInfo_NoInstance()
		{
			string machine = "machine";
			string category = "category";
			string counter = "counter";
			string fullname = "\\" + machine + "\\" + category + "\\" + counter;

			var target = new CounterInfo(fullname);

			Assert.AreEqual(machine, target.Machine);
			Assert.AreEqual(category, target.Category);
			Assert.AreEqual(counter, target.Counter);
			Assert.AreEqual(fullname, target.Fullname);
			Assert.AreEqual(null, target.Instance);
		}

		/// <summary>
		/// Test with instance
		///</summary>
		[TestMethod]
		public void CounterInfo_WithInstance()
		{
			string machine = "machine";
			string category = "category";
			string counter = "counter";
			string instance = "instance";
			string fullname = "\\" + machine + "\\" + category + "(" + instance + ")" + "\\" + counter;

			var target = new CounterInfo(fullname);

			Assert.AreEqual(machine, target.Machine);
			Assert.AreEqual(category, target.Category);
			Assert.AreEqual(counter, target.Counter);
			Assert.AreEqual(fullname, target.Fullname);
			Assert.AreEqual(instance, target.Instance);
		}

		/// <summary>
		/// Test with null
		///</summary>
		[TestMethod]
		[ExpectedException(typeof(ArgumentException))]
		public void CounterInfo_NullString()
		{
			var target = new CounterInfo(null);
		}

		/// <summary>
		/// Test with instance
		///</summary>
		[TestMethod]
		[ExpectedException(typeof(ArgumentException))]
		public void CounterInfo_MissingData()
		{
			string fullname = "\\machine\\category";
			var target = new CounterInfo(fullname);
		}
	}
}
